<?php
/**
 * AST classes for EL
 */
class Code {

    function Code ($l)
    {
        $this->l = $l; 
    }
    
    function dumpPHP ()
    {
        return $this->l->dumpPHP();
    }

}
class OuterString {

    function OuterString ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return "'".addslashes($this->l)."'";
    }

}
class ParenExpr {

    function ParenExpr ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return "(".$this->l->dumpPHP().")";
    }

}
class Digit {

    function Digit ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return $this->l;
    }

}
class String {

    function String ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return '"'.str_replace('"','\"',$this->l).'"';
    }

}
class Param {

    function Param ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP();
    }

}
class Id {

    function Id ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return '__id($env, $actionform, array(\''.$this->l.'\'))';
    }

    function dump ()
    {
        return '\''.$this->l.'\'';
    }

}
class Variable { // treat a variable like an id

    function Variable ($l)
    {
        $this->l = $l; 
    }

//    function dumpPHP ()
//    {
//        return '$'.$this->l;
//    }

    function dumpPHP ()
    {
        return '__id($env, $actionform, array(\''.$this->l.'\'))';
    }

    function dump ()
    {
        return '\''.$this->l.'\'';
    }

}
class ArrayT {

    function ArrayT ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return '['.$this->l->dumpPHP().']';
    }

    function dump ()
    {
        return '('.$this->l->dumpPHP().')';
    }

}
class Negation {

    function Negation ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return '!'.$this->l->dumpPHP();
    }

}
class TrueKeyword {

    function TrueKeyword ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return $this->l;
    }

}
class FalseKeyword {

    function FalseKeyword ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return $this->l;
    }

}
class NegNumber {

    function NegNumber ($l)
    {
        $this->l = $l; 
    }

    function dumpPHP ()
    {
        return '-'.$this->l;
    }

}

class ELPart {

    function ELPart ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        $l = (get_class($this->l) == 'Code')?'('.$this->l->dumpPHP().')':$this->l->dumpPHP();
        $r = (get_class($this->r) == 'Code')?'('.$this->r->dumpPHP().')':$this->r->dumpPHP();
        return $l.'.'.$r;
    }

}
class PlusExpr {

    function PlusExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'+'.$this->r->dumpPHP();
    }

}
class MinusExpr {

    function MinusExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'-'.$this->r->dumpPHP();
    }

}
class MultExpr {

    function MultExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'*'.$this->r->dumpPHP();
    }

}
class ModExpr {

    function ModExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'%'.$this->r->dumpPHP();
    }

}
class DivExpr {

    function DivExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'/'.$this->r->dumpPHP();
    }

}
class ConcatExpr {

    function ConcatExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().' . '.$this->r->dumpPHP();
    }

}
class FunExpr {

    function FunExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l.'('.($this->r != null?$this->r->dumpPHP():'').')';
    }

}
class MethodExpr {

    function MethodExpr ($obj, $method, $params)
    {
        $this->obj = $obj; 
        $this->method = $method; 
        $this->params = $params;
    }

    function dumpPHP ()
    {
        return $this->obj->dumpPHP().'->'.$this->method.'('.($this->params!=null?$this->params->dumpPHP():'').')';
    }

    function dump ()
    {
        return $this->dumpPHP();
    }

}
class IdMethodExpr {

    function IdMethodExpr ($method, $id)
    {
        $this->method = $method; 
        $this->r = $id;
    }

    function dumpPHP ()
    {
        return '__arrayaccess('.$this->method->dump().', array('.((get_class($this->r)=='ArrayPair'||get_class($this->r)=='ArrayT')?'array('.$this->r->dump().')':$this->r->dump()).'))';
    }

    function dump ()
    {
        return $this->dumpPHP();
    }

}
class ArrayExpr {

    function ArrayExpr ($array)
    {
        $this->array = $array;
    }

    function dumpPHP ()
    {
        return 'array(' . ($this->array!=null?(is_object($this->array)?$this->array->dumpPHP():var_export($this->array)):'').')';
    }

}
class AssozArrayPair {

    function AssozArrayPair ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'=>'. $this->r->dumpPHP();
    }

}
class ParamPair {

    function ParamPair ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().','.$this->r->dumpPHP();
    }

}
class VarArray { // treat variable like an id 

    function VarArray ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

//    function dumpPHP ()
//    {
//        return $this->l->dumpPHP().$this->r->dumpPHP();
//    }
    function dumpPHP ()
    {
        
        return '__id($env, $actionform, array('.$this->l->dump().', '.((get_class($this->r)=='ArrayPair'||get_class($this->r)=='ArrayT')?'array('.$this->r->dump().')':$this->r->dump()).'))';
    }

    function dump ()
    {
        return $this->l->dump().', '.((get_class($this->r)=='ArrayPair'||get_class($this->r)=='ArrayT')?'array('.$this->r->dump().')':$this->r->dump());
    }

}
class IdPair {

    function IdPair ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        if (get_class($this->l) == 'MethodExpr')
            return '__id($env, '.$this->l->dump().', array('.((get_class($this->r)=='ArrayPair'||get_class($this->r)=='ArrayT')?'array('.$this->r->dump().')':$this->r->dump()).'))';
        else
            return '__id($env, $actionform, array('.$this->l->dump().', '.((get_class($this->r)=='ArrayPair'||get_class($this->r)=='ArrayT')?'array('.$this->r->dump().')':$this->r->dump()).'))';
    }

    function dump ()
    {
        return $this->l->dump().', '.((get_class($this->r)=='ArrayPair'||get_class($this->r)=='ArrayT')?'array('.$this->r->dump().')':$this->r->dump());
    }

}
class ArrayPair {

    function ArrayPair ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().$this->r->dumpPHP();
    }

    function dump ()
    {
        return $this->l->dump().', '.$this->r->dump().'';
    }

}
class EqExpr {

    function EqExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'=='.$this->r->dumpPHP();
    }

}
class NeqExpr {

    function NeqExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'!='.$this->r->dumpPHP();
    }

}
class LeqExpr {

    function LeqExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'<='.$this->r->dumpPHP();
    }

}
class GeqExpr {

    function GeqExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'>='.$this->r->dumpPHP();
    }

}
class GtExpr {

    function GtExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'>'.$this->r->dumpPHP();
    }

}
class LtExpr {

    function LtExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'<'.$this->r->dumpPHP();
    }

}
class OrExpr {

    function OrExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'||'.$this->r->dumpPHP();
    }

}
class EOrExpr {

    function EOrExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'|'.$this->r->dumpPHP();
    }

}
class AndExpr {

    function AndExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'&&'.$this->r->dumpPHP();
    }

}
class EAndExpr {

    function EAndExpr ($l, $r)
    {
        $this->l = $l; 
        $this->r = $r; 
    }

    function dumpPHP ()
    {
        return $this->l->dumpPHP().'&'.$this->r->dumpPHP();
    }

}
class ConditionalExpr {

    function ConditionalExpr ($l, $r, $b)
    {
        $this->l = $l; 
        $this->r = $r; 
        $this->b = $b; 
    }

    function dumpPHP ()
    {
        return '('.$this->l->dumpPHP().'?'.$this->r->dumpPHP().':'.$this->b->dumpPHP().')';
    }

}
